package com.heima.wemedia.listener;

import com.alibaba.fastjson.JSON;
import com.heima.constants.WmNewsConstants;
import com.heima.schedule.dtos.Task;
import com.heima.wemedia.mapper.WmNewsMapper;
import com.heima.wemedia.pojos.WmNews;
import com.heima.wemedia.service.WmNewsScanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class TaskListener {

    @Autowired
    private WmNewsMapper wmNewsMapper;
    @Autowired
    private WmNewsScanService wmNewsScanService;

    @KafkaListener(topics = WmNewsConstants.LEIMA_TASK_EXECUTOR)
    public void taskExec(String message) {
        log.info("接收到消息：{}", message);
        // 反序列化
        WmNews wmNews = JSON.parseObject(message, WmNews.class);
        //调用扫描文章
        wmNewsScanService.saveAppArticle(wmNews);
    }
}
